package widgets

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/widget"
)

// ScriptInputConfig 脚本输入框配置
type ScriptInputConfig struct {
	Label         string
	PlaceHolder   string
	MinRows       int
	ReadOnly      bool
	DynamicHeight bool
	EntryConfig   LinedEntryConfig // 可选，如果未提供则使用其他字段
}

// ScriptInputField 脚本输入字段
type ScriptInputField struct {
	Entry    *LinedEntry
	FormItem *widget.FormItem
}

// NewScriptInputField 创建脚本输入字段
func NewScriptInputField(config ScriptInputConfig) *ScriptInputField {
	// 构建LinedEntryConfig
	entryConfig := config.EntryConfig

	// 如果EntryConfig为空，使用传统字段构建
	if entryConfig.MinRows == 0 {
		entryConfig = LinedEntryConfig{
			MinRows:       config.MinRows,
			ReadOnly:      config.ReadOnly,
			DynamicHeight: config.DynamicHeight,
			MaxHeight:     800,
			Wrapping:      fyne.TextWrapOff,
		}
	}

	entry := NewLinedEntry(entryConfig)
	entry.SetPlaceHolder(config.PlaceHolder)

	formItem := widget.NewFormItem(config.Label, entry)

	return &ScriptInputField{
		Entry:    entry,
		FormItem: formItem,
	}
}
